#include <iostream>

using namespace std;

const int N = 2e5 + 10;

typedef long long LL;

//以a[i]为结尾的所有子区间中，最大的子段和
//用f[i]减去[1,i-1]中所有前缀和的最小值prevmin即可
//prevmin = min(prevmin, f[i])

int n;
LL f[N]; // 前缀和数组

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int x; cin >> x;
		f[i] = f[i - 1] + x; // 预处理前缀和
	}

	LL ret = -1e18;
	LL prevmin = 0;
	for(int i = 1; i <= n; i++)
	{
		ret = max(ret, f[i] - prevmin);
		prevmin = min(prevmin, f[i]);
	}

	cout << ret << endl;

	return 0;
}



